<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<{include file='backend/lib/meta.html'}>
<link rel="stylesheet" type="text/css" href="public/theme/backend/css/verydows.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/css/main.css" />
  <link rel="stylesheet" type="text/css" href="public/theme/backend/css/goods.css" />
  <link rel="stylesheet" type="text/css" href="public/theme/backend/webupload/webuploader.css" />
  <link rel="stylesheet" type="text/css" href="public/theme/backend/css/datetimepicker.css"/>
  <style type="text/css">
    .px80{width: 50px;height: 50px;}
  </style>
<script type="text/javascript" src="public/script/jquery.js"></script>
<script type="text/javascript" src="public/theme/backend/js/verydows.js"></script>
  <script type="text/javascript" src="public/theme/backend/js/list.js"></script>
  <script type="text/javascript">
    $(function(){searchRes(1)});
    //搜索商品
    function searchRes(page_id){
      var dataset = {
        cate_id: $('#cate_id').val(),
        brand_id: $('#brand_id').val(),
        sign_id: $('#sign_id').val(),
        status: $('#status').val(),
        kw: $('#kw').val(),
        sort_id: $('#sort_id').val(),
        page: page_id,
        pernum: 12,
      };
      $.asynList("<{url m=$MOD c='goods' a='index' step='search'}>", dataset, function(data){
        if(data.status == 'success'){
          juicer.register('format_date', function(v){return formatTimestamp(v, 'y-m-d<br />h:i:s');});
          $('#rows').append(juicer($('#table-tpl').html(), data));
          $('#rows tr').vdsRowHover();
          $('#rows tr:even').addClass('even');
          if(data.paging != null) $('#rows').append(juicer($('#paging-tpl').html(), data));
        }else{
          $('#rows').append("<div class='nors mt5'>未找到相关数据记录...</div>");
        }
      });
    }
    //翻页
    function pageturn(page_id){searchRes(page_id);}
  </script>
<script type="text/javascript">
  $(function(){
    $('#start_date').datetimepicker({
      format:'Y-m-d',
      formatDate:'Y-m-d',
      allowBlank:true,
      onShow:function(ct){
        this.setOptions({maxDate:$('#end_date').val()? $('#end_date').val(): false});
      },
      timepicker:false,
    });
    $('#end_date').datetimepicker({
      format:'Y-m-d',
      formatDate: 'Y-m-d',
      allowBlank:true,
      onShow:function(ct){
        this.setOptions({minDate:$('#start_date').val()? $('#start_date').val():false})
      },
      timepicker:false
    });
  });

function submitForm(){
  $('#name').vdsFieldChecker({rules: {required:[true, '分类优惠券不能为空'], maxlen:[60, '优惠券名称不能超过60个字符']}});
  $('#start_date').vdsFieldChecker({rules: {required:[true, '开始时间不能为空']}});
  $('#end_date').vdsFieldChecker({rules: {required:[true, '失效时间不能为空']}});
  $('#greater_than').vdsFieldChecker({rules: {required:[true, '满减金额不能为空']}});
  $('#amount').vdsFieldChecker({rules: {required:[true, '优惠不能为空']}});
  $('#num').vdsFieldChecker({rules: {required:[true, '发行数量不能为空']}});
  $('#goods_use').vdsFieldChecker({rules: {required:[true, '适用范围不能为空']}});
  $('form').vdsFormChecker();
}
</script>
</head>
<body>
<{if $_GET['a'] == 'voucheradd'}>
<div class="content">
  <div class="loc"><h2><i class="icon"></i>添加新优惠券</h2></div>
  <form method="post" action="<{url m=$MOD c='goods_cate' a='voucheradd' step='submit'}>">
    <div class="box">
      <div class="module">
        <table class="dataform">
          <tr>
            <th width="110">优惠券名称</th>
            <td><input class="w200 txt" name="name" id="name" type="text" /></td>
          </tr>
          <tr>
            <th>开始时间</th>
            <td>
              <input class="date w150 txt" name="start_date" id="start_date" type="text" value="" placeholder="开始时间" />
            </td>
          </tr>
          <tr>
            <th>失效时间</th>
            <td>
              <input class="date w150 txt" name="end_date" id="end_date" type="text" value="" placeholder="失效时间" />
            </td>
          </tr>
          <tr>
            <th>满减金额</th>
            <td><input value="" class="w100 txt" name="greater_than" id="greater_than" type="text"onkeyup="clearNoNum(this)" /> 高于该金额时可以使用</td>
          </tr>
          <tr>
            <th>优惠金额</th>
            <td><input value="" class="w100 txt" name="amount" id="amount" type="text"onkeyup="clearNoNum(this)" /></td>
          </tr>
          <tr>
            <th>发行数量</th>
            <td><input value="" class="w100 txt" name="num" id="num" type="text"onkeyup="clearNoNum(this)" /></td>
          </tr>
          <tr>
            <th>适用商品</th>
            <td><input value="0" class="w150 txt" name="goods_use" id="goods_use" type="text" /> 0表示全场通用
              <p><br><button type="button" class="ubtn btn" onclick="show_product()">选择商品</button></p>
            </td>
          </tr>
        </table>
      </div>
      <div class="submitbtn">
        <button type="button" class="ubtn btn" onclick="submitForm()">保存并提交</button>
        <button type="reset" class="fbtn btn">重置表单</button>
      </div>
    </div>
  </form>
</div>
<{else}>
<div class="content">
  <div class="loc"><h2><i class="icon"></i>编辑优惠券:<font class="ml5">[<{$rs.id}>]</font></h2></div>
  <form method="post" action="<{url m=$MOD c='goods_cate' a='voucheredit' id=$rs.id step='submit'}>">
    <div class="box">
      <div class="module">
        <table class="dataform">
          <tr>
            <th width="110">优惠券名称
              <input type="hidden" value="<{$rs.id}>" name="id" /></th>
            <td><input class="w200 txt" value="<{$rs.vname}>" name="name" id="name" type="text" /></td>
          </tr>
          <tr>
            <th>开始时间</th>
            <td>
              <input class="date w150 txt" value="<{date('Y-m-d', $rs.start)}>" name="start_date" id="start_date" type="text" value="" placeholder="开始时间" />
            </td>
          </tr>
          <tr>
            <th>失效时间</th>
            <td>
              <input class="date w150 txt" value="<{date('Y-m-d', $rs.end)}>" name="end_date" id="end_date" type="text" value="" placeholder="失效时间" />
            </td>
          </tr>
          <tr>
            <th>满减金额</th>
            <td><input value="<{$rs.greater_than}>" class="w100 txt" name="greater_than" id="greater_than" type="text"onkeyup="clearNoNum(this)" /> 高于该金额时可以使用</td>
          </tr>
          <tr>
            <th>优惠金额</th>
            <td><input value="<{$rs.amount}>" class="w100 txt" name="amount" id="amount" type="text"onkeyup="clearNoNum(this)" /></td>
          </tr>
          <tr>
            <th>发行数量</th>
            <td><input value="<{$rs.num}>" class="w100 txt" name="num" id="num" type="text"onkeyup="clearNoNum(this)" /></td>
          </tr>
          <tr>
            <th>适用商品</th>
            <td><input value="<{$rs.goods_use}>" class="w150 txt" name="goods_use" id="goods_use" type="text" /> 0表示全场通用
              <p><br><button type="button" class="ubtn btn" onclick="show_product()">选择商品</button></p>
            </td>
          </tr>
        </table>
      </div>
      <div class="submitbtn">
        <button type="button" class="ubtn btn" onclick="submitForm()">保存并更新</button>
        <button type="reset" class="fbtn btn">重置表单</button>
      </div>
    </div>
  </form>
</div>
<{/if}>

<div class="impoper cut hide" id="imulpoper">
  <a class="close"></a>
  <div class="th"><font class="c888">选择商品</font></div>
  <div class="imuler cut">
    <div class="imulqu">
      <table id="rows">
      </table>
    </div>
  </div>
  <div class="bom ta-c mt5"><a class="fbtn btn" onclick="sure_check()">确定</a></div>
</div>

<script type="text/template" id="table-tpl">
  <table class="datalist">
    <tr>
      <th width="60">编号</th>
      <th class="ta-l">商品名称</th>
      <th width="150">图片</th>
      <th width="130">价格 <font class='c999'>(元)</font></th>
      <th width="100">库存</th>
      <th width="100">状态</th>
      <th width="100">操作</th>
    </tr>
    {@each list as v}
    <tr>
      <td width="40">${v.goods_id}</td>
      <td class="ta-l">
        <a class="blue" href="index.php?m=<{$MOD}>&c=goods&a=edit&id=${v.goods_id}">${v.goods_name}</a>
      </td>
      <td><img class="px80" src="<{$goodsurl}>${v.goods_image}"></td>
      <td class="red">${v.now_price}</td>
      <td>${v.stock_qty}</td>
      <td>{@if v.status == 1}<font class="green">上架</font>{@else}<font class="red">下架</font>{@/if}</td>
      <td class="c888"><input type="checkbox" name="goods_check_id" value="${v.goods_id}"></td>
    </tr>
    {@/each}
  </table>
</script>
<{include file='backend/lib/paging.html'}>

<script type="text/javascript">
  function show_product(){
    $('#imulpoper').vdsMidst({wrapper:$(window), gotop:-220, goleft:-200}).show().find('a.close').on('click', function(){
      $('#imulpoper').hide();
    });
  }

  function sure_check(){
    var str = '';
    $('input[name="goods_check_id"]:checked').each(function(){
      str += $(this).val() + ',';
    });
    var goods_use = $("#goods_use").val();
    str = str.substring(0, str.length-1);
    if(goods_use == 0){
      $("#goods_use").val(str);
    }else{
      $("#goods_use").append(str);
    }
    $('#imulpoper').hide();
  }
</script>

<script type="text/javascript" src="public/script/juicer.js"></script>
<script type="text/javascript" src="public/theme/backend/js/datetimepicker.js"></script>
</body>
</html>
